Programming Languages Section

Fortran Programming Language

What is Fortran Programming Language
Post by Amina Delali, January 24th, 2023

Some Facts

Fortran is a general purpose programming language, and beset suited for scientific computing and numeric computations. The language passed through several versioning and standardizations processes. The last standardized Fortran version is Fortran 2018

Fortran is a natively parallel programming language, and also part of the CUDA Fortran toolchain. Used in diverse applications types like weather forecasting, and DNA and atomic structures simulations.

There are also multiple compilers available, some of them are free, and others are commercial. The one we are going to used is the GNU Fortran Compiler (gfortran) which free and open source. Concerning the standards compliance, gfortran is fully compliant with the Fortran 95, and also implements features from Fortran 2003 and Fortran 2008.



How to install it

  • on Windows:

    To install gfortran on Windows, you can follow these steps:

    • Download and install MSYS2, the software distribution and building platform for Windows. Just go to the installation page, download the installer, and run the installer by following th on screen steps.
    • The MSYS2 terminal will automatically launch after the installation. If it doen't, just write msys on the start search box. Then run the following command: pacman -S mingw-w64-ucrt-x86_64-gcc
    • Before continuing you have to update MSYS2 by the following command (on the same terminal): pacman -Suy The process of the update may ask you to close the terminal. So accept by answering Y. Then open it again from the start menu by typing msys on the search box.
    • Now, to install gfortran run the following command: pacman -Su gcc-fortran
    • To check the installation run this command: gfortran --version

  • on ubuntu :

    The installation of gfortran on Ubuntu is simple and straightforward. All you have to do is to run these commands on the terminal:

    • For the installation: sudo apt update
      sudo apt upgrade
      sudo apt install gfortran
    • To check the installation run this command: gfortran --version

The Hello World Example

  • Create a new file hello.f95. Write in that file the following code and save it:
    program helloworld
         print *, "Hello World!"
    end program helloworld
  • Open the MSYS2 terminal if you are on Windows, or simply the terminal if you are on Ubuntu and change the current directory to where you saved your code. Don't forget to replace every "\" character, by a "/" character. For example, on Windows: cd c:
    cd users/amina
  • To compile the code, run the following command: gfortran -c hello.f95 It will generate the object file hello.o
  • To create an executable for Windows run this command: gfortran -o hello.exe hello.o To create an executable for Ubuntu run this command: gfortran -o hello hello.o
  • To run the code on Windows: ./hello.exe To run it on Ubuntu: ./hello


Something to say ?

If you want to add something about the language or about this post, please feel free to do it by commenting below 🙂 .